package com.codeoss.framework.view.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.converter.IConverter;
import com.codeoss.framework.converter.IConverterStore;
import com.codeoss.framework.expression.Expression;
import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.Date;
import com.codeoss.framework.view.service.IVariableService;

@Service
public class DateComponentService extends ComponentService {
	@Autowired
    private IVariableService variableService;
	@Autowired
	private IConverterStore converterStore;
	@Override
	public void processValue(YunContext yunContext, Component component,Map<String,String> paraMap,Map<String,Object> dataMap) {
		// TODO Auto-generated method stub
		Date date=(Date)component;
		if(paraMap.containsKey(date.getId())) {
			String sValue=paraMap.get(date.getId());
			IConverter converter=converterStore.getConverter("date");
			Object value=converter.convertStringToObject(sValue);
			variableService.setVariableValue(yunContext, date.getVarName(), value);
		}
	}
	
	@Override
	public void processEvent(YunContext yunContext, Component component, String eventType) {
		super.processEvent(yunContext, component, eventType);
		Date date=(Date)component;
		if ("changeEvent".equals(eventType)) {
			Expression onChangeExpression = date.getOnChangeExpression();
			if (onChangeExpression != null) {
				executeEventExpression(yunContext, component, onChangeExpression,null);
			}
		}
	}
}
